package yb.ecp.fast.user.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yb.ecp.fast.user.dao.entity.AuthDO;
import yb.ecp.fast.user.dao.entity.MenuDO;
import yb.ecp.fast.user.dao.entity.TmpAuthDO;
import yb.ecp.fast.user.dao.entity.TmpMenuDO;
import yb.ecp.fast.user.dao.mapper.MenuMapper;
import yb.ecp.fast.user.dao.mapper.TmpAuthMapper;
import yb.ecp.fast.user.dao.mapper.TmpMenuMapper;
import yb.ecp.fast.user.service.VO.AuthorizedQueryParamCache;

import java.util.List;

@Service
public class MenuCacheService {

    @Autowired
    MenuMapper menuMapper;
    @Autowired
    private TmpMenuMapper tmpMenuMapper;
    @Autowired
    private TmpAuthMapper tmpAuthMapper;

//    @CaffeineLocalCache(keyExt = "queryAuthorizedQueryParamCache", expireTime = 3000, refreshTime = 60)
    public AuthorizedQueryParamCache queryAuthorizedQueryParamCache() {
        //===============这一块数据都是为了后面调用方法不用再去数据库查找了======
        //查询全部的菜单到内存中
        List<MenuDO> allMenues = menuMapper.getAllList();
        //查询全部的权限模板关系表IUS_TMP_AUTH到内内存中
        List<TmpMenuDO> allTmpMenues = tmpMenuMapper.queryAllList();
        //查询全部的角色与menu关系表数据IUS_TMP_AUTH
        List<TmpAuthDO> allTmpAuths = tmpAuthMapper.queryAllList();
        //菜单权限表数据IUS_AUTH和 IUS_MENU_AUTH联表查询
        List<AuthDO> menuAuths = menuMapper.selectAuthList();
        return new AuthorizedQueryParamCache(allMenues, allTmpMenues, allTmpAuths, menuAuths);
    }
}
